﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace 线程和并发
{
    class Program
    {
        static void Main(string[] args)
        {

            // 使用无参数委托ThreadStart
            Thread t = new Thread(Go);
            t.Start();

            // 使用带参数委托ParameterizedThreadStart
            Thread t2 = new Thread(GoWithParam);
            t2.Start("Message from main.");

            t2.Join();// 等待线程t2完成。

            Console.WriteLine("Thread t2 has ended!");
            Console.ReadKey();


        }

        static void Go()
        {
            Console.WriteLine("Go!");
        }

        static void GoWithParam(object msg)
        {
            Console.WriteLine("Go With Param! Message: " + msg);
            Thread.Sleep(1000);// 模拟耗时操作
        }
    }
}
